package com.jian.android.autojipai.app.helper;


import android.content.Context;

import com.jian.android.autojipai.R;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import net.lingala.zip4j.ZipFile;

/* loaded from: classes.dex */
public class ZipTool {

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class ZipToolInstance {
        private static final ZipTool instance = new ZipTool();

        private ZipToolInstance() {
        }
    }

    private ZipTool() {
    }

    public static ZipTool getInstance() {
        return ZipToolInstance.instance;
    }

    public void unZipFile(Context context) {
        try {
            ZipFile zipFile = new ZipFile(new File(context.getExternalFilesDir(null) + File.separator + "tfl.zip").getAbsolutePath());
            if (zipFile.isEncrypted()) {
                zipFile.setPassword("150429".toCharArray());
            }
            zipFile.extractAll(context.getFilesDir().getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace();
            StringWriter stringWriter = new StringWriter();
            e.printStackTrace(new PrintWriter((Writer) stringWriter, true));
            FileTool.getInstance().saveException(context, stringWriter.toString(), "JY异常.txt");
        }
    }

    public void saveZip(Context context) {
        InputStream openRawResource = context.getResources().openRawResource(R.raw.tfl);
        File file = new File(context.getExternalFilesDir(null) + File.separator + "tfl.zip");
        try {
            if (file.exists()) {
                file.delete();
            }
            if (file.exists()) {
                return;
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            byte[] bArr = new byte[openRawResource.available()];
            while (true) {
                int read = openRawResource.read(bArr);
                if (read != -1) {
                    fileOutputStream.write(bArr, 0, read);
                } else {
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    openRawResource.close();
                    return;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            StringWriter stringWriter = new StringWriter();
            e.printStackTrace(new PrintWriter((Writer) stringWriter, true));
            FileTool.getInstance().saveException(context, stringWriter.toString(), "SAVEZIP异常.txt");
        }
    }
}
